<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
  Class: Api::V3::TopicsController
  
    &mdash; Ruby China API 文档
  
</title>

  <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  pathId = "Api::V3::TopicsController";
  relpath = '../../';
</script>


  <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>


  </head>
  <body>
    <div class="nav_wrap">
      <iframe id="nav" src="../../class_list.html?1"></iframe>
      <div id="resizer"></div>
    </div>

    <div id="main" tabindex="-1">
      <div id="header">
        <div id="menu">
  
    <a href="../../_index.html">Index (T)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../../Api.html" title="Api (module)">Api</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../V3.html" title="Api::V3 (module)">V3</a></span></span>
     &raquo; 
    <span class="title">TopicsController</span>
  
</div>

        <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../../class_list.html">

        <svg width="24" height="24">
          <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
        </svg>
    </a>
  
</div>
        <div class="clear"></div>
      </div>

      <div id="content"><h1>Class: Api::V3::TopicsController
  
  
  
</h1>
<div class="box_info">
  
  <dl>
    <dt>Inherits:</dt>
    <dd>
      <span class="inheritName"><span class='object_link'><a href="ApplicationController.html" title="Api::V3::ApplicationController (class)">ApplicationController</a></span></span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">ActionController::Base</li>
          
            <li class="next"><span class='object_link'><a href="ApplicationController.html" title="Api::V3::ApplicationController (class)">ApplicationController</a></span></li>
          
            <li class="next">Api::V3::TopicsController</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
    </dd>
  </dl>
  

  
  
  
  
  

  

  
  <dl>
    <dt>Defined in:</dt>
    <dd>app/controllers/api/v3/topics_controller.rb</dd>
  </dl>
  
</div>








  
    <h2>
      Instance Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#action-instance_method" title="#action (instance method)">#<strong>action</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>更多功能 注意类型有不同的权限，详见 GET /api/v3/topics/:id 返回的 abilities.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#ban-instance_method" title="#ban (instance method)">#<strong>ban</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>屏蔽话题 (Admin only) [废弃] 请用 POST /api/v3/topics/:id/action.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#create-instance_method" title="#create (instance method)">#<strong>create</strong>  &#x21d2; TopicDetailSerializer </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>创建新话题.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#create_replies-instance_method" title="#create_replies (instance method)">#<strong>create_replies</strong>  &#x21d2; ReplySerializer </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>创建对话题的回帖.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#destroy-instance_method" title="#destroy (instance method)">#<strong>destroy</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>删除话题.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#favorite-instance_method" title="#favorite (instance method)">#<strong>favorite</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>收藏话题.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#follow-instance_method" title="#follow (instance method)">#<strong>follow</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>关注话题.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#index-instance_method" title="#index (instance method)">#<strong>index</strong>  &#x21d2; Array&lt;TopicSerializer&gt; </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>获取话题列表，类似网站的 /topics 的结构，支持多种排序方式。.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#replies-instance_method" title="#replies (instance method)">#<strong>replies</strong>  &#x21d2; Array&lt;ReplySerializer] </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>获取话题的回帖列表.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#show-instance_method" title="#show (instance method)">#<strong>show</strong>  &#x21d2; TopicDetailSerializer </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>获取话题详情（不含回帖）.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#unfavorite-instance_method" title="#unfavorite (instance method)">#<strong>unfavorite</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>取消收藏话题.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#unfollow-instance_method" title="#unfollow (instance method)">#<strong>unfollow</strong>  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>取消关注话题.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#update-instance_method" title="#update (instance method)">#<strong>update</strong>  &#x21d2; TopicDetailSerializer </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>更新话题.</p>
</div></span>
  
</li>

      
    </ul>
  


  
  
  
  
  
  
  
  
  <h3 class="inherited">Methods inherited from <span class='object_link'><a href="ApplicationController.html" title="Api::V3::ApplicationController (class)">ApplicationController</a></span></h3>
  <p class="inherited"><span class='object_link'><a href="ApplicationController.html#can%3F-instance_method" title="Api::V3::ApplicationController#can? (method)">#can?</a></span>, <span class='object_link'><a href="ApplicationController.html#current_ability-instance_method" title="Api::V3::ApplicationController#current_ability (method)">#current_ability</a></span>, <span class='object_link'><a href="ApplicationController.html#current_user-instance_method" title="Api::V3::ApplicationController#current_user (method)">#current_user</a></span>, <span class='object_link'><a href="ApplicationController.html#error!-instance_method" title="Api::V3::ApplicationController#error! (method)">#error!</a></span>, <span class='object_link'><a href="ApplicationController.html#error_404!-instance_method" title="Api::V3::ApplicationController#error_404! (method)">#error_404!</a></span>, <span class='object_link'><a href="ApplicationController.html#meta-instance_method" title="Api::V3::ApplicationController#meta (method)">#meta</a></span>, <span class='object_link'><a href="ApplicationController.html#optional!-instance_method" title="Api::V3::ApplicationController#optional! (method)">#optional!</a></span>, <span class='object_link'><a href="ApplicationController.html#requires!-instance_method" title="Api::V3::ApplicationController#requires! (method)">#requires!</a></span></p>

  
  
  
  

  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="action-instance_method">
  
    #<strong>action</strong>  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>更多功能 注意类型有不同的权限，详见 GET /api/v3/topics/:id 返回的 abilities</p>

<p>POST /api/v3/topics/:id/action?type=:type</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>type</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>动作类型, ban - 屏蔽话题, normal - 取消屏蔽, excellent - 加精华, unexcellent - 取消精华, close
- 关闭回复, open - 开启回复</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 222</span>

<span class='kw'>def</span> <span class='id identifier rubyid_action'>action</span>
  <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_can?'>can?</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='comma'>,</span> <span class='ivar'>@topic</span><span class='rparen'>)</span>

  <span class='kw'>case</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span>
  <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>excellent</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_excellent!'>excellent!</span>
  <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>unexcellent</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_unexcellent!'>unexcellent!</span>
  <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>normal</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_normal!'>normal!</span>
  <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ban</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_ban!'>ban!</span>
  <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>close</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_close!'>close!</span>
  <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>open</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_open!'>open!</span>
  <span class='kw'>end</span>
  <span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span> <span class='label'>ok:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="ban-instance_method">
  
    #<strong>ban</strong>  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>屏蔽话题 (Admin only)</p>
<dl class="rdoc-list label-list"><dt>废弃
<dd>
<p>请用 POST /api/v3/topics/:id/action</p>
</dd></dl>

<p>POST /api/v3/topics/:id/ban</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


211
212
213
214
215</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 211</span>

<span class='kw'>def</span> <span class='id identifier rubyid_ban'>ban</span>
  <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>当前用户没有屏蔽别人话题的权限，具体请参考官网的说明。</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_can?'>can?</span><span class='lparen'>(</span><span class='symbol'>:ban</span><span class='comma'>,</span> <span class='ivar'>@topic</span><span class='rparen'>)</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_ban!'>ban!</span>
  <span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span> <span class='label'>ok:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="create-instance_method">
  
    #<strong>create</strong>  &#x21d2; <tt>TopicDetailSerializer</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>创建新话题</p>

<p>POST /api/v3/topics</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>title</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>标题, [required]</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>node_id</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>节点编号, [required]</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>body</span>
      
      
        <span class='type'>(<tt>Markdown</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>格式的正文, [required]</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>TopicDetailSerializer</tt>)</span>
      
      
      
    </li>
  
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


81
82
83
84
85
86
87
88
89
90
91
92
93</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 81</span>

<span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span>
  <span class='id identifier rubyid_requires!'>requires!</span> <span class='symbol'>:title</span>
  <span class='id identifier rubyid_requires!'>requires!</span> <span class='symbol'>:body</span>
  <span class='id identifier rubyid_requires!'>requires!</span> <span class='symbol'>:node_id</span>

  <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>当前登录的用户没有发帖权限，具体请参考官网的相关说明。</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_can?'>can?</span><span class='lparen'>(</span><span class='symbol'>:create</span><span class='comma'>,</span> <span class='const'>Topic</span><span class='rparen'>)</span>

  <span class='ivar'>@topic</span> <span class='op'>=</span> <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_topics'>topics</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>title:</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:title</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:body</span><span class='rbracket'>]</span><span class='rparen'>)</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_node_id'>node_id</span> <span class='op'>=</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:node_id</span><span class='rbracket'>]</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_save!'>save!</span>

  <span class='id identifier rubyid_render'>render</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>show</span><span class='tstring_end'>&quot;</span></span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="create_replies-instance_method">
  
    #<strong>create_replies</strong>  &#x21d2; <tt>ReplySerializer</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>创建对话题的回帖</p>

<p>POST /api/v3/topics/:id/replies</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>body</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p><a href="required">回帖内容，</a></p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>ReplySerializer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>创建的回帖信息</p>
</div>
      
    </li>
  
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


162
163
164
165
166
167
168
169
170
171
172
173</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 162</span>

<span class='kw'>def</span> <span class='id identifier rubyid_create_replies'>create_replies</span>
  <span class='id identifier rubyid_doorkeeper_authorize!'>doorkeeper_authorize!</span>

  <span class='id identifier rubyid_requires!'>requires!</span> <span class='symbol'>:body</span>

  <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>当前用户没有回帖权限，具体请参考官网的说明。</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_can?'>can?</span><span class='lparen'>(</span><span class='symbol'>:create</span><span class='comma'>,</span> <span class='const'>Reply</span><span class='rparen'>)</span>

  <span class='ivar'>@reply</span> <span class='op'>=</span> <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_replies'>replies</span><span class='period'>.</span><span class='id identifier rubyid_build'>build</span><span class='lparen'>(</span><span class='label'>body:</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:body</span><span class='rbracket'>]</span><span class='rparen'>)</span>
  <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_user_id'>user_id</span> <span class='op'>=</span> <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span>
  <span class='ivar'>@reply</span><span class='period'>.</span><span class='id identifier rubyid_save!'>save!</span>
  <span class='id identifier rubyid_render'>render</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>api/v3/replies/show</span><span class='tstring_end'>&quot;</span></span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="destroy-instance_method">
  
    #<strong>destroy</strong>  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>删除话题</p>

<p>DELETE /api/v3/topics/:id</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


129
130
131
132
133</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 129</span>

<span class='kw'>def</span> <span class='id identifier rubyid_destroy'>destroy</span>
  <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_can?'>can?</span><span class='lparen'>(</span><span class='symbol'>:destroy</span><span class='comma'>,</span> <span class='ivar'>@topic</span><span class='rparen'>)</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_destroy_by'>destroy_by</span><span class='lparen'>(</span><span class='id identifier rubyid_current_user'>current_user</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span> <span class='label'>ok:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="favorite-instance_method">
  
    #<strong>favorite</strong>  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>收藏话题</p>

<p>POST /api/v3/topics/:id/favorite</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


194
195
196
197</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 194</span>

<span class='kw'>def</span> <span class='id identifier rubyid_favorite'>favorite</span>
  <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_favorite_topic'>favorite_topic</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span> <span class='label'>ok:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="follow-instance_method">
  
    #<strong>follow</strong>  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>关注话题</p>

<p>POST /api/v3/topics/:id/follow</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


178
179
180
181</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 178</span>

<span class='kw'>def</span> <span class='id identifier rubyid_follow'>follow</span>
  <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_follow_topic'>follow_topic</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span> <span class='label'>ok:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="index-instance_method">
  
    #<strong>index</strong>  &#x21d2; <tt>Array&lt;TopicSerializer&gt;</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>获取话题列表，类似网站的 /topics 的结构，支持多种排序方式。</p>

<p>GET /api/v3/topics</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>type</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>排序类型, default: `last_actived`, %w(last_actived recent no_reply popular
excellent)</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>node_id</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>节点编号，如果有给，就会只去节点下的话题</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>offset</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>default: 0</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>limit</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>default: 20, range: 1..150</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Array&lt;TopicSerializer&gt;</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 19</span>

<span class='kw'>def</span> <span class='id identifier rubyid_index'>index</span>
  <span class='id identifier rubyid_optional!'>optional!</span> <span class='symbol'>:type</span><span class='comma'>,</span> <span class='label'>default:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>last_actived</span><span class='tstring_end'>&quot;</span></span>
  <span class='id identifier rubyid_optional!'>optional!</span> <span class='symbol'>:node_id</span>
  <span class='id identifier rubyid_optional!'>optional!</span> <span class='symbol'>:offset</span><span class='comma'>,</span> <span class='label'>default:</span> <span class='int'>0</span>
  <span class='id identifier rubyid_optional!'>optional!</span> <span class='symbol'>:limit</span><span class='comma'>,</span> <span class='label'>default:</span> <span class='int'>20</span><span class='comma'>,</span> <span class='label'>values:</span> <span class='int'>1</span><span class='op'>..</span><span class='int'>150</span>

  <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span>

  <span class='kw'>if</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:node_id</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
    <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='const'>Topic</span>
    <span class='kw'>if</span> <span class='id identifier rubyid_current_user'>current_user</span>
      <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@topics</span><span class='period'>.</span><span class='id identifier rubyid_without_nodes'>without_nodes</span><span class='lparen'>(</span><span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_block_node_ids'>block_node_ids</span><span class='rparen'>)</span>
      <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@topics</span><span class='period'>.</span><span class='id identifier rubyid_without_users'>without_users</span><span class='lparen'>(</span><span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_block_user_ids'>block_user_ids</span><span class='rparen'>)</span>
    <span class='kw'>else</span>
      <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@topics</span><span class='period'>.</span><span class='id identifier rubyid_without_hide_nodes'>without_hide_nodes</span>
    <span class='kw'>end</span>
  <span class='kw'>else</span>
    <span class='ivar'>@node</span> <span class='op'>=</span> <span class='const'>Node</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:node_id</span><span class='rbracket'>]</span><span class='rparen'>)</span>
    <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@node</span><span class='period'>.</span><span class='id identifier rubyid_topics'>topics</span>
  <span class='kw'>end</span>

  <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@topics</span><span class='period'>.</span><span class='id identifier rubyid_without_ban'>without_ban</span><span class='period'>.</span><span class='id identifier rubyid_fields_for_list'>fields_for_list</span><span class='period'>.</span><span class='id identifier rubyid_includes'>includes</span><span class='lparen'>(</span><span class='symbol'>:user</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_scope_method_by_type'>scope_method_by_type</span><span class='rparen'>)</span>
  <span class='kw'>if</span> <span class='qwords_beg'>%w[</span><span class='tstring_content'>no_reply</span><span class='words_sep'> </span><span class='tstring_content'>popular</span><span class='tstring_end'>]</span></span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span><span class='rparen'>)</span>
    <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@topics</span><span class='period'>.</span><span class='id identifier rubyid_last_actived'>last_actived</span>
  <span class='kw'>elsif</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>excellent</span><span class='tstring_end'>&quot;</span></span>
    <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@topics</span><span class='period'>.</span><span class='id identifier rubyid_recent'>recent</span>
  <span class='kw'>end</span>

  <span class='ivar'>@topics</span> <span class='op'>=</span> <span class='ivar'>@topics</span><span class='period'>.</span><span class='id identifier rubyid_offset'>offset</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:offset</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_limit'>limit</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:limit</span><span class='rbracket'>]</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="replies-instance_method">
  
    #<strong>replies</strong>  &#x21d2; <tt>Array&lt;ReplySerializer]</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>获取话题的回帖列表</p>

<p>GET /api/v3/topics/:id/replies</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>offset</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>default: 0</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>limit</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>default: 20, range: 1..150</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Array&lt;ReplySerializer]</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


142
143
144
145
146
147
148
149
150
151
152
153
154</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 142</span>

<span class='kw'>def</span> <span class='id identifier rubyid_replies'>replies</span>
  <span class='kw'>if</span> <span class='id identifier rubyid_request'>request</span><span class='period'>.</span><span class='id identifier rubyid_post?'>post?</span>
    <span class='id identifier rubyid_create_replies'>create_replies</span>
    <span class='kw'>return</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:limit</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='int'>20</span>

  <span class='ivar'>@replies</span> <span class='op'>=</span> <span class='const'>Reply</span><span class='period'>.</span><span class='id identifier rubyid_unscoped'>unscoped</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>topic_id:</span> <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_order'>order</span><span class='lparen'>(</span><span class='symbol'>:id</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_includes'>includes</span><span class='lparen'>(</span><span class='symbol'>:user</span><span class='rparen'>)</span>
  <span class='ivar'>@replies</span> <span class='op'>=</span> <span class='ivar'>@replies</span><span class='period'>.</span><span class='id identifier rubyid_offset'>offset</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:offset</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_limit'>limit</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:limit</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='rparen'>)</span>
  <span class='ivar'>@user_liked_reply_ids</span> <span class='op'>=</span> <span class='id identifier rubyid_current_user'>current_user</span><span class='op'>&amp;.</span><span class='id identifier rubyid_like_reply_ids_by_replies'>like_reply_ids_by_replies</span><span class='lparen'>(</span><span class='ivar'>@replies</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
  <span class='ivar'>@meta</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>user_liked_reply_ids:</span> <span class='ivar'>@user_liked_reply_ids</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="show-instance_method">
  
    #<strong>show</strong>  &#x21d2; <tt>TopicDetailSerializer</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>获取话题详情（不含回帖）</p>

<p>GET /api/v3/topics/:id</p>

<p>“`json { followed: &#39;是否已关注&#39;, liked: &#39;是否已赞&#39;, favorited:
&#39;是否已收藏&#39; } “`</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>id</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>话题编号</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>TopicDetailSerializer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>此外 meta 里面包含当前用户对此话题的状态</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


60
61
62
63
64
65
66
67
68
69
70
71</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 60</span>

<span class='kw'>def</span> <span class='id identifier rubyid_show'>show</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_hits'>hits</span><span class='period'>.</span><span class='id identifier rubyid_incr'>incr</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span>
  <span class='ivar'>@meta</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>followed:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='label'>liked:</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='label'>favorited:</span> <span class='kw'>false</span> <span class='rbrace'>}</span>

  <span class='kw'>if</span> <span class='id identifier rubyid_current_user'>current_user</span>
    <span class='comment'># 处理通知
</span>    <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_read_topic'>read_topic</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='rparen'>)</span>
    <span class='ivar'>@meta</span><span class='lbracket'>[</span><span class='symbol'>:followed</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_follow_topic?'>follow_topic?</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='rparen'>)</span>
    <span class='ivar'>@meta</span><span class='lbracket'>[</span><span class='symbol'>:liked</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_like_topic?'>like_topic?</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='rparen'>)</span>
    <span class='ivar'>@meta</span><span class='lbracket'>[</span><span class='symbol'>:favorited</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_favorite_topic?'>favorite_topic?</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='rparen'>)</span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="unfavorite-instance_method">
  
    #<strong>unfavorite</strong>  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>取消收藏话题</p>

<p>POST /api/v3/topics/:id/unfavorite</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


202
203
204
205</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 202</span>

<span class='kw'>def</span> <span class='id identifier rubyid_unfavorite'>unfavorite</span>
  <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_unfavorite_topic'>unfavorite_topic</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span> <span class='label'>ok:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="unfollow-instance_method">
  
    #<strong>unfollow</strong>  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>取消关注话题</p>

<p>POST /api/v3/topics/:id/unfollow</p>


  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


186
187
188
189</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 186</span>

<span class='kw'>def</span> <span class='id identifier rubyid_unfollow'>unfollow</span>
  <span class='id identifier rubyid_current_user'>current_user</span><span class='period'>.</span><span class='id identifier rubyid_unfollow_topic'>unfollow_topic</span><span class='lparen'>(</span><span class='ivar'>@topic</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span> <span class='label'>ok:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="update-instance_method">
  
    #<strong>update</strong>  &#x21d2; <tt>TopicDetailSerializer</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>更新话题</p>

<p>POST /api/v3/topics/:id</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>title</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>标题, [required]</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>node_id</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>节点编号, [required]</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>body</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>Markdown 格式的正文, [required]</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>TopicDetailSerializer</tt>)</span>
      
      
      
    </li>
  
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'app/controllers/api/v3/topics_controller.rb', line 103</span>

<span class='kw'>def</span> <span class='id identifier rubyid_update'>update</span>
  <span class='id identifier rubyid_requires!'>requires!</span> <span class='symbol'>:title</span>
  <span class='id identifier rubyid_requires!'>requires!</span> <span class='symbol'>:body</span>
  <span class='id identifier rubyid_requires!'>requires!</span> <span class='symbol'>:node_id</span>

  <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="ApplicationController/AccessDenied.html" title="Api::V3::ApplicationController::AccessDenied (class)">AccessDenied</a></span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_can?'>can?</span><span class='lparen'>(</span><span class='symbol'>:update</span><span class='comma'>,</span> <span class='ivar'>@topic</span><span class='rparen'>)</span>

  <span class='kw'>if</span> <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_lock_node'>lock_node</span> <span class='op'>==</span> <span class='kw'>false</span> <span class='op'>||</span> <span class='id identifier rubyid_admin?'>admin?</span>
    <span class='comment'># 锁定接点的时候，只有管理员可以修改节点
</span>    <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_node_id'>node_id</span> <span class='op'>=</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:node_id</span><span class='rbracket'>]</span>

    <span class='kw'>if</span> <span class='id identifier rubyid_admin?'>admin?</span> <span class='op'>&amp;&amp;</span> <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_node_id_changed?'>node_id_changed?</span>
      <span class='comment'># 当管理员修改节点的时候，锁定节点
</span>      <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_lock_node'>lock_node</span> <span class='op'>=</span> <span class='kw'>true</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_title'>title</span> <span class='op'>=</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:title</span><span class='rbracket'>]</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span> <span class='op'>=</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:body</span><span class='rbracket'>]</span>
  <span class='ivar'>@topic</span><span class='period'>.</span><span class='id identifier rubyid_save!'>save!</span>

  <span class='id identifier rubyid_render'>render</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>show</span><span class='tstring_end'>&quot;</span></span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

      <div id="footer">
  Generated on Thu Jun 14 19:16:09 2018 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.9.12 (ruby-2.5.1).
</div>

    </div>
  </body>
</html>